package com.hsq.reflection.Class_;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class ReflectionUtils {
    public static void main(String[] args) throws ClassNotFoundException {
//        api_01();
        api_02();
    }
    public static void api_02() throws ClassNotFoundException {
        Class perCls = Class.forName("com.hsq.reflection.Class_.Person");
        Field[] declaredFieldsfields = perCls.getDeclaredFields();
        for (Field declaredField : declaredFieldsfields) {
            System.out.println("本类所有属性=" + declaredField.getName()
            + " 该属性的修饰符值 = " + declaredField.getModifiers()
            + " 该属性的类型 = " + declaredField.getType());
        }

        Method[] declaredMethods = perCls.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println("方法所有属性=" + declaredMethod.getName()
                    + " 该方法的修饰符值 = " + declaredMethod.getModifiers()
                    + " 该方法的返回类型 = " + declaredMethod.getReturnType());

            //输出当前方法的参数组成情况
            Parameter[] parameters = declaredMethod.getParameters();
            for (Parameter parameter : parameters) {
                System.out.println(declaredMethod.getName() + "该方法参数" + parameter);
            }
        }

    }


    public static void api_01() throws ClassNotFoundException {
        Class personCls = Class.forName("com.hsq.reflection.Class_.Person");
        System.out.println(personCls.getName());
        System.out.println(personCls.getSimpleName());
        //只能获得public属性
        Field[] fields = personCls.getFields();
        for (Field field : fields) {
            System.out.println("本类和父类属性" + field.getName());
        }
        //getDeclaredFields可以获得所有属性
        Field[] declaredFieldsfields = personCls.getDeclaredFields();
        for (Field declaredField: declaredFieldsfields) {
            System.out.println("本类所有属性, 不会返回父类属性" + declaredField.getName());
        }

        Method[] methods = personCls.getMethods();
        for (Method method: methods) {
            System.out.println("本类和父类public方法：" + method.getName());
        }
        Method[] declaredMethod = personCls.getDeclaredMethods();
        for (Method method : declaredMethod) {
            System.out.println("本类方法：" + method.getName());
        }
        Constructor<?>[] constructor = personCls.getConstructors();
        for (Constructor<?> constructor1 : constructor) {
            System.out.println("本类public构造器：" + constructor1.getName());
        }
        Constructor[] declaredConstructors = personCls.getDeclaredConstructors();
        for (Constructor declaredConstructor : declaredConstructors) {
            System.out.println("本类所有构造器：" + declaredConstructor.getName());
        }

        System.out.println(personCls.getPackage());
        Class superclass = personCls.getSuperclass();
        System.out.println("父类Class对象" + superclass);
        Class[] interfaces = personCls.getInterfaces();
        for (Class anInterface : interfaces) {
            System.out.println("接口信息：" + anInterface);
        }

        Annotation[] annotation = personCls.getAnnotations();
        for (Annotation annotation1 : annotation) {
            System.out.println("注释信息：" + annotation1);
        }



    }
}

class A {
    public String habby;

    public void AA() {

    }
}

interface IA {

}
interface IB {

}
@Deprecated
class Person extends A implements IA, IB{
    public String name;
    protected static int age;
    String job;
    private double sal;

    private Person() {

    }

    public Person(String name) {
        this.name = name;
    }

    public void m1(String name, int age, String habby) {

    }
    protected boolean m2() {
        return true;
    }
    void m3() {

    }
    private void m4() {

    }
}
